package cn.tpshion.devops.controller;

import cn.tpshion.devops.common.Result;
import cn.tpshion.devops.domain.dto.TaskWorkDTO;
import cn.tpshion.devops.domain.entity.TaskWork;
import cn.tpshion.devops.service.TaskService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/task")
public class TaskController {

    @Resource
    private TaskService taskService;

    /**
     * 保存流程数据
     */
    @PostMapping("/saveFlowData")
    public Result<TaskWork> saveFlowData(@Valid @RequestBody TaskWork taskWork){
        return Result.ok(taskService.saveFlowData(taskWork));
    }

    /**
     * 获取流程数据
     */
    @PostMapping("/getFlowData")
    public Result<TaskWork> getFlowData(@Valid @RequestBody TaskWorkDTO dto){
        return Result.ok(taskService.getFlowData(dto));
    }

    /**
     * 获取所有流程数据
     */
    @PostMapping("/getFlowList")
    public Result<List<TaskWork>> getFlowList(){
        return Result.ok(taskService.getFlowList());
    }

    /**
     * 获取分支列表
     */
    @PostMapping("/branchList")
    public Result<List<String>> branchList(@Valid @RequestBody TaskWorkDTO dto){
        return Result.ok(taskService.branchList(dto));
    }

    /**
     * 删除流程
     */
    @PostMapping("/deleteFlow")
    public Result deleteFlow(@Valid @RequestBody TaskWorkDTO dto){
        taskService.deleteFlow(dto);
        return Result.ok();
    }
}
